import React from 'react';
import { connect } from 'dva';
import styles from './TeacherAttendanceRoute.css';
import TeacherAttendance from '../components/teacher/TeacherAttendance';

function TeahcerAttendanceRoute({teacher:{teachers,loading},dispatch,attendance}) {
    let attendanceProps = {
        teachers,
        attendance,
        teacherLoading:loading
    }
  return (
    <div className={styles.normal}>
      <TeacherAttendance {...attendanceProps} onTeacherSelect={(selected)=>{
          let needload=true;
          if(attendance.attendanceMap[selected.id]){
              needload=false;
          }
          dispatch({type:'attendance/select',payload:{
              selected,
              needload
          }})
      }}/>
    </div>
  );
}

function mapStateToProps({teacher,attendance}) {
  return {teacher,attendance};
}

export default connect(mapStateToProps)(TeahcerAttendanceRoute);
